package com.woniu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.woniu.pojo.House;
import com.woniu.pojo.Leasefile;
import com.woniu.pojo.Tenement;
import com.woniu.service.TenancyService;
import com.woniu.service.TenementService;

@RestController
@RequestMapping("tmc")
public class TenementController {
		@Autowired
		private TenementService tenementService;
		@Autowired
		private TenancyService tenancyService;
		@RequestMapping("getTenementByid")
		public Tenement getTenementByid(Integer t_id) {
			
			Tenement tenement=tenementService.getTenementByid(t_id);
			return tenement;
		}
		@RequestMapping("getTenementBytenement_id")
		public Tenement getTenementBytenement_id(String tenement_id) {
			
			Tenement tenement=tenementService.getTenementBytenement_id(tenement_id);
			return tenement;
		}
		@RequestMapping("list")
		public Map<String,Object> getAllTenement(Integer start,Integer length,Tenement tenement){

			PageInfo<Tenement> pageInfo = tenementService.getAllTenementByPage((start/length)+1, length, tenement);

			 Map<String,Object> map=new HashMap<String,Object>();
		    
		        map.put("recordsTotal", pageInfo.getTotal());
		      
		        map.put("recordsFiltered", pageInfo.getTotal());
		       
		        map.put("data", pageInfo.getList());
				return map;
			
		}
		@RequestMapping("deletetenementByid")
		public String deleteTenementByid(Integer t_id) {
			System.out.println();
			tenementService.deleteTenementByid(t_id);
			return "删除成功";
		}
		@RequestMapping("deleteTenementsById")
		public String deleteTenementsById(String t_ids) {
		
			tenementService.deleteTenementsById(t_ids);
			return "删除"+t_ids+"成功";
		}
		@RequestMapping("addtenement")
		public String addTenancy(Tenement tenement) {
			//System.out.println(leasefile.toString());
			tenementService.addTenement(tenement);
			return "添加成功";
		}

		@RequestMapping("getTenency")
		public List<Leasefile> getTenency() {

			List <Leasefile>list=tenancyService.getAllTenancy();
			return list;
		}
		@RequestMapping("UpdatetenementInfo")
		public String UpdateTenancyInfo(Tenement tenement) {

			tenementService.UpdateTenementInfo(tenement);
			return "修改成功";
		}
}
